// 重载
type Message={
    id:number;
    // type:string;
    type:MessageType;
    sendmessage:string
}
enum MessageType{
    "Image"="Image",
    "Audio"="Audio"
}
let messages:Message[] = [
    {
        id:1,
        type:MessageType.Image,
        sendmessage:"你好呀,今晚咱们一起去三里屯吧",
    },
    {
        id:2,
        type:MessageType.Audio,
        sendmessage:"朝辞白帝彩云间,千里江陵一日还",
    },
    {
        id:3,
        type:MessageType.Audio,
        sendmessage:"你好呀,张无忌",
    },
    {
        id:4,
        type:MessageType.Image,
        sendmessage:"今晚王牌对王牌节目咋样?",
    },
    {
        id:5,
        type:MessageType.Image,
        sendmessage:"刘老根苦练舞台绝技",
    },
]


// 函数重载
function searchMsg(condition:MessageType):Message[]; // 重载签名
function searchMsg(condition:number):Message|undefined;

// 实现签名---将上面的consdition的MessageType和number都放在下面的condition后面 返回类型Message[]和:Message|undefined;也放在下面的返回类型后面--缺一不可
function searchMsg(condition:MessageType|number):Message|undefined|Message[]{// 实现签名
    if(typeof condition==="number"){
        return messages.find(msg=>condition === msg.id)
    }else{
        return messages.filter(msg=>condition === msg.type)
    }
}
// (searchMsg(1) as Message)
console.log(searchMsg(1));

searchMsg(MessageType.Image).forEach(msg =>{
    console.log('msg',msg);
})
export {}